<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="1、CPU数据库一般是IO密集型的，其性能瓶颈在于IO。数据库服务器的选购偏内存，CPU可以适当降低其要求。 InnoDB存储引擎相关后台线程： show engine innodb status\G;     插入缓冲区线程 http:&#x2F;&#x2F;www.cnblogs.com&#x2F;yuyue2014&#x2F;p&#x2F;3802779.htmlInnoDB insert buffer thread 线程主要是更新非唯一索">
<meta property="og:type" content="article">
<meta property="og:title" content="MySQL技术内幕-InnoDB存储引擎读写笔记(性能调优)">
<meta property="og:url" content="https://www.codingw.net/posts/5b656c60.html">
<meta property="og:site_name" content="中间件兴趣圈">
<meta property="og:description" content="1、CPU数据库一般是IO密集型的，其性能瓶颈在于IO。数据库服务器的选购偏内存，CPU可以适当降低其要求。 InnoDB存储引擎相关后台线程： show engine innodb status\G;     插入缓冲区线程 http:&#x2F;&#x2F;www.cnblogs.com&#x2F;yuyue2014&#x2F;p&#x2F;3802779.htmlInnoDB insert buffer thread 线程主要是更新非唯一索">
<meta property="og:locale">
<meta property="og:image" content="https://img-blog.csdn.net/20170717201302449?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlc3RpZ2VkaW5n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center">
<meta property="og:image" content="">
<meta property="og:image" content="https://img-blog.csdn.net/20170717201359777?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlc3RpZ2VkaW5n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center">
<meta property="og:image" content="">
<meta property="og:image" content="https://img-blog.csdn.net/20170717201612086?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlc3RpZ2VkaW5n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center">
<meta property="og:image" content="">
<meta property="article:published_time" content="2020-11-14T14:35:01.000Z">
<meta property="article:modified_time" content="2021-04-26T12:32:41.027Z">
<meta property="article:author" content="中间件兴趣圈">
<meta property="article:tag" content="中间件">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://img-blog.csdn.net/20170717201302449?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlc3RpZ2VkaW5n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://www.codingw.net/posts/5b656c60.html"/>





  <title>MySQL技术内幕-InnoDB存储引擎读写笔记(性能调优) | 中间件兴趣圈</title>
  








<meta name="generator" content="Hexo 5.4.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">中间件兴趣圈</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">微信搜『中间件兴趣圈』，回复『Java』获取200本优质电子书</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://www.codingw.net/posts/5b656c60.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="中间件兴趣圈">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">MySQL技术内幕-InnoDB存储引擎读写笔记(性能调优)</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-11-14T22:35:01+08:00">
                2020-11-14
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/mysql/" itemprop="url" rel="index">
                    <span itemprop="name">mysql</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/posts/5b656c60.html" class="leancloud_visitors" data-flag-title="MySQL技术内幕-InnoDB存储引擎读写笔记(性能调优)">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>次
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <div id="vip-container"><h2 id="1、CPU"><a href="#1、CPU" class="headerlink" title="1、CPU"></a>1、CPU</h2><p>数据库一般是IO密集型的，其性能瓶颈在于IO。数据库服务器的选购偏内存，CPU可以适当降低其要求。</p>
<p>InnoDB存储引擎相关后台线程：</p>
<p>show engine innodb status\G;</p>
<p>  <img src="https://img-blog.csdn.net/20170717201302449?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlc3RpZ2VkaW5n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="img"><img src="" alt="点击并拖拽以移动"></p>
<ul>
<li>插入缓冲区线程 <a target="_blank" rel="noopener" href="http://www.cnblogs.com/yuyue2014/p/3802779.html">http://www.cnblogs.com/yuyue2014/p/3802779.html</a><br>InnoDB insert buffer thread 线程主要是更新非唯一索引的索引数据，避免频繁随机的读写索引文件。（索引数据存放在表默认表空间中）</li>
<li>log thread : InnoDB的默认指的就是redo日志,log thread 就是写 redo 日志的线程。</li>
<li>read thread | write thread 读、写日志线程（文件 《—-》内存）</li>
</ul>
<p> 根据CPU适当调节innodb_read_io_threads与innodb_write_io_threads</p>
<h2 id="2、内存"><a href="#2、内存" class="headerlink" title="2、内存"></a>2、内存</h2><p>内存的大小最能直接反应数据库的性能。InnoDB存储引擎既缓存数据，又缓存索引（存放在数据文件中，表空间），并放入一个很大的缓冲池中(InnoDB Buffer Pool)。</p>
<p>innodb_buffer_pool的大小如果能等于数据文件的大小，则能缓存所有的数据文件，性能会得到极高的提升（innodb_buffer_pool_size）,如何判断当前数据库的内存是否达到了瓶颈了呢。</p>
<p>mysql提供  show global status 命令查看系统运行状况监控，（INFORMATION_SCHEMA GLOBAL_STATUS临时表）。</p>
<p><img src="https://img-blog.csdn.net/20170717201359777?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlc3RpZ2VkaW5n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="img"><img src="" alt="点击并拖拽以移动"></p>
<p>关注如下参数：</p>
<ul>
<li><p>innodb_buffer_pool_reads: 从物理磁盘读取页的次数</p>
</li>
<li><p>innodb_buffer_pool_read_ahead:预读的次数</p>
</li>
<li><p>innodb_buffer_pool_read_ahead_evicted:预读的页，但没有被读取就从缓冲区被替换的也的数量，一般用来判断预读的效率。</p>
</li>
<li><p>innodb_buffer_pool_read_requests:从缓冲池中读取页的次数（可以理解为缓冲命中次数）</p>
</li>
<li><p>innodb_data_read:总共读入的字节数</p>
</li>
<li><p>innodb_data_reads:发起读请求的次数</p>
</li>
</ul>
 <span id="more"></span>

<p>预读的效率：(1 -  (innodb_buffer_pool_read_ahead / innodb_buffer_pool_read)) * 100 %</p>
<p>InnoDB缓存命中率： innodb_buffer_pool_read_requests /  ( innodb_buffer_pool_read_requests + innodb_buffer_pool_reads  + innodb_buffer_pool_read_ahead )  * 100 %</p>
<p>InnoDB缓存命中率通常要保持在99%以上，才表明内存无压力，这样性能杠杠的。</p>
<p>平均每次读取的字节数= innodb_data_read/innodb_data_reads</p>
<p>内存大于数据文件，并不意味着没有IO操作，Innodb会定时刷脏（将被修改的页刷写到数据文件），并且每次事务提交，会写redo日志。</p>
<h2 id="3、磁盘对数据库性能的影响"><a href="#3、磁盘对数据库性能的影响" class="headerlink" title="3、磁盘对数据库性能的影响"></a>3、磁盘对数据库性能的影响</h2><p>数据库是IO密集型应用，推荐使用raid10(磁盘冗余阵列)</p>
<h2 id="4、SQL语句优化"><a href="#4、SQL语句优化" class="headerlink" title="4、SQL语句优化"></a>4、SQL语句优化</h2><p>SQL语句的优化点基本上会落到是否能利用索引这个问题上来。</p>
<ul>
<li>养成好的SQL使用习惯</li>
</ul>
<p>​      a、禁止使用 select *，应写需要的数据字段。</p>
<p>​      b、尽量使用exists代替in</p>
<ul>
<li>尽量利用索引来加速SQL数据的查询效率</li>
</ul>
<p>以下情况将无法利用索引： </p>
<ul>
<li><p>不支持 != 表达式，如果使用不等于，无法利用到索引。索引的存储结构是B+树，支持等值查询与范围查询。</p>
</li>
<li><p>like ‘%a%’无法利用索引，但’a%’可以使用索引。<br>原因分析，索引的存储结构是B+树，叶子节点存放数据，数据本身是排序的，输入值必须是一个明确的值，方便对比，a%开头的查询，是可以用a当查询关键字首先定位记录的，但%a%无法定位。</p>
</li>
<li><p>复合索引，查询条件必须包含第一列（最左列）<br>道理是一样的，索引的优势就是天生是排序的，查询类似于二分查询（每比较一次，就会缩短查询范围）。<br>例如有两列的复合索引类似(  1, 1  ) (  1, 3  ) (  2, 1  )  (  2, 5  )  (  3, 1  ) 只有包含第一列，整个二元序列就是有序的，但如果剔除第一列，那序列为  1,3,1,5,1，无序序列的查找，复杂度为o(n)。</p>
</li>
<li><p>对字段使用表达式或函数允许，将无法使用索引<br>索引建立原则</p>
<ul>
<li>列高选择性（重复率低）</li>
<li>频繁查询的列</li>
<li>order by 或 group by字段（利用索引的有序性）</li>
</ul>
</li>
</ul>
<h2 id="5、MySQL执行计划解读"><a href="#5、MySQL执行计划解读" class="headerlink" title="5、MySQL执行计划解读"></a>5、MySQL执行计划解读</h2><p>MySQL提供explain查看查询语句的执行计划，使用案例如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">EXPLAIN SELECT</span><br><span class="line">  t.id,</span><br><span class="line">  t.order_no,</span><br><span class="line">  t.total_price,</span><br><span class="line">  t.seller_id,</span><br><span class="line">  t.creator,</span><br><span class="line">  t.create_time</span><br><span class="line">FROM</span><br><span class="line">  (</span><br><span class="line">   SELECT a.id,</span><br><span class="line">      a.order_no,</span><br><span class="line">      a.total_price,</span><br><span class="line">      a.seller_id,</span><br><span class="line">      a.creator,</span><br><span class="line">      a.create_time</span><br><span class="line">    FROM</span><br><span class="line">      es_order a</span><br><span class="line">    WHERE</span><br><span class="line">     a.seller_id &#x3D; 24</span><br><span class="line">    LIMIT 20,</span><br><span class="line">    10</span><br><span class="line">  ) t</span><br><span class="line"></span><br><span class="line">INNER JOIN es_order_item b ON b.order_id &#x3D; t.id</span><br></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdn.net/20170717201612086?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlc3RpZ2VkaW5n/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="img"><img src="" alt="点击并拖拽以移动">相关字段：id、select_type、table、type、prossible_keys、key、ken_len、ref、rows、Extr</p>
<ul>
<li><p>id : 执行顺序，数字越大，先执行。</p>
</li>
<li><p>select_type: (只是标记为查询类型)</p>
<ul>
<li>simple : 查询中不包含子查询或union</li>
<li>primary:若查询中包含任何复杂的子查询，最外层查询标记为：PRIMARY</li>
<li>subquery:子查询</li>
<li>derived:驱动表，不是真实的物理表，但不同于临时表</li>
<li>union:</li>
<li>union result</li>
</ul>
</li>
<li><p>type:访问类型，重点关注<br>取值如下：all、index、range、ref、  eq_ref、  const system、null</p>
<ul>
<li>all : 全表扫描</li>
<li>index: Full Index Scan,index与all的区别为index只遍历索引树。<br>例如：(select a.id from es_order a)</li>
<li>range:索引范围扫描，常见于索引字段上的  between &gt; &lt;  like( like ‘a%’)</li>
<li>ref : 非唯一索引的等值匹配，例如a.seller_id=24 (seller_id上建有索引)</li>
<li>eq_ref:唯一索引的等值匹配</li>
<li>const、system:当MySQL对查询某部分进行优化，并转换为一个常量时，使用这些类型访问explain select a.id,a.name from es_order a where a.id=8078</li>
<li>null : 不需要访问表，索引等。</li>
</ul>
</li>
<li><p>possible_keys</p>
<p> 指出mysql能使用哪个索引能在表中找到行，查询涉及到的字段若存在索引，则会列出，但不一定使用</p>
</li>
<li><p>key （重点关注）<br>使用到的索引</p>
</li>
<li><p>key_len (索引用到的长度)</p>
</li>
<li><p>ref 索引匹配的情况（列）【无需太关注】</p>
</li>
<li><p>rows<br>本次查询，预计需要扫描的行数</p>
</li>
<li><p>Extra  额外的说明信息</p>
</li>
<li><p>using index (covering Index)</p>
</li>
<li><p>using where<br>表示mysql服务器从存储引擎收到记录后，进行“后过滤”，如果未使用索引，提醒</p>
</li>
<li><p>Using temporary</p>
</li>
</ul>
<p>​      表示使用了临时表空间（排序、分组）</p>
<ul>
<li>Using filesort</li>
</ul>
<p>​      Mysql中无法利用索引完成的排序操作成为文件排序。</p>
<h2 id="6、数据库设计心得"><a href="#6、数据库设计心得" class="headerlink" title="6、数据库设计心得"></a>6、数据库设计心得</h2><p>1、数据库的表的设计方法论为理解ER关系</p>
<p>   一对一、一对多、多对对（分拆成两个1对多关系，也就是引入一个关系实体）</p>
<p>2）适当打破数据库第三范式<br>适当增加冗余字段，减少表的连接操作。<br>举例：订单表中有商品ID，由于订单反映的当时下单时商品的信息，我们完成可以增加一个冗余字段，商品名称goods_name,这样在展示订单信息时，无需join商品信息表。（冗余字段的增加可能会带来数据的不一致性，所以要结合实际情况，不能为了冗余而冗余）</p>
<p>3）数据库字段类型选择</p>
<p>尽量选择满足需求的最小长度。比如订单状态，可以使用tinyint,而无需使用int。这样的直接好处就是减少数据行的长度，每页能存储更多的数据行，IO效率得到提高。（性能是一个积累的过程）</p>
<p>4）表的垂直分割<br>将一个表的信息分割成多个表，这样主要是保证频繁使用的主表每行的数据尽量少，每页存放更多数据行，提高IO读效率。表分割后，如果每次查询主表，都需要连接查询从表，那就没有必要进行垂直分割。</p>
<p>举例：比如一条资讯信息，咨询的内容使用的类型为(text)，在实际使用时，一般是先出资讯列表，然后点击到每一条资讯时，才去查询资讯内容，此时可以将咨询内容单独分割出一张表，在咨询主表中冗余一个字段（摘要），存放咨询内容的部分信息，用于列表展示。</p>
<p>反例：<br>比如一条评论，有评论内容，类型为text,此时就没必要单独将评论内容抽取出来，因为每次显示评论时，基本上都要查看全部的评论内容，如果分开，会进行多边连接，性能反而受影响。</p>
<p>5）表设计阶段应该考虑索引的建立</p>
<p>应根据系统相关需求，在创建表时建立必要的索引。</p>
</div>

			<script src="https://my.openwrite.cn/js/readmore.js" type="text/javascript"></script>
			<script>
			var isMobile = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i);
			if (!isMobile) {
			    var btw = new BTWPlugin();
			    btw.init({
			        "id": "vip-container",
			        "blogId": "18019-1573088808868-542",
			        "name": "中间件兴趣圈",
			        "qrcode": "https://img-blog.csdnimg.cn/20190314214003962.jpg",
			        "keyword": "more"
			    });
			}
			</script>
		
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/posts/4d11b991.html" rel="next" title="数据异构之 Canal 初探（技巧篇）">
                <i class="fa fa-chevron-left"></i> 数据异构之 Canal 初探（技巧篇）
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/posts/3f9b27cb.html" rel="prev" title="MySQL技术内幕-InnoDB存储引擎读书笔记(MySQL日志文件)">
                MySQL技术内幕-InnoDB存储引擎读书笔记(MySQL日志文件) <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name"></p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">139</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">18</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1%E3%80%81CPU"><span class="nav-number">1.</span> <span class="nav-text">1、CPU</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2%E3%80%81%E5%86%85%E5%AD%98"><span class="nav-number">2.</span> <span class="nav-text">2、内存</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3%E3%80%81%E7%A3%81%E7%9B%98%E5%AF%B9%E6%95%B0%E6%8D%AE%E5%BA%93%E6%80%A7%E8%83%BD%E7%9A%84%E5%BD%B1%E5%93%8D"><span class="nav-number">3.</span> <span class="nav-text">3、磁盘对数据库性能的影响</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4%E3%80%81SQL%E8%AF%AD%E5%8F%A5%E4%BC%98%E5%8C%96"><span class="nav-number">4.</span> <span class="nav-text">4、SQL语句优化</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5%E3%80%81MySQL%E6%89%A7%E8%A1%8C%E8%AE%A1%E5%88%92%E8%A7%A3%E8%AF%BB"><span class="nav-number">5.</span> <span class="nav-text">5、MySQL执行计划解读</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93%E8%AE%BE%E8%AE%A1%E5%BF%83%E5%BE%97"><span class="nav-number">6.</span> <span class="nav-text">6、数据库设计心得</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">中间件兴趣圈</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("NNEhOL0iOcflg8f1U3HUqiCq-gzGzoHsz", "7kSmkbbb3DktmHALlShDsBUF");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  

  

  

  

</body>
</html>
